package io.renren.modules.webapi.controller;


import io.renren.common.annotation.SysLog;
import io.renren.common.utils.R;
import io.renren.common.utils.SmsUtil;
import io.renren.common.utils.StringUtil;
import io.renren.modules.project.entity.ProjectAuthachEntity;
import io.renren.modules.project.entity.ProjectExpachEntity;
import io.renren.modules.project.entity.ProjectSituationEntity;
import io.renren.modules.project.service.ProjectAuthachService;
import io.renren.modules.project.service.ProjectExpachService;
import io.renren.modules.project.service.ProjectSituationService;
import io.renren.modules.project.vo.AuthachVoEntity;
import io.renren.modules.webapi.vo.SmsVoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Random;

@RestController
@RequestMapping("/webapi/ach")
public class AchController {

    @Autowired
    private ProjectExpachService projectExpachService;

    @Autowired
    private ProjectAuthachService projectAuthachService;

    @Autowired
    private ProjectSituationService projectSituationService;

    /**
     * 获取成果最新的内容列表
     */
    @RequestMapping("/info")
    public R info(@RequestParam Map<String, Object> params){
        String projectNo = params.get("projectNo").toString();
        List<ProjectExpachEntity> list = projectExpachService.queryLastList(params);
        ProjectAuthachEntity entity = projectAuthachService.queryByPro(projectNo);
        ProjectSituationEntity situationEntity = projectSituationService.queryByProjectNo(projectNo);

        return R.ok().put("list", list).put("ach",entity).put("situation",situationEntity);
    }

    /**
     * 客户签收成果单
     */
    @SysLog("提交调查表")
    @RequestMapping("/update")
    public R update(@RequestBody AuthachVoEntity authVo){
        ProjectAuthachEntity authachEntity = authVo.getAuthachEntity();
        authachEntity.setOrigin("微信");
        projectAuthachService.update(authachEntity);
        ProjectSituationEntity situationEntity = projectSituationService.queryByProjectNo(authVo.getProjectNo());
        situationEntity.setIsSign(1L);
        projectSituationService.updateById(situationEntity);
        return R.ok();
    }
}
